#==============================================================================
# ** Main
#------------------------------------------------------------------------------
#  After defining each class, actual processing begins here.
#==============================================================================

begin
  module GlobalMethods
    @txt = ''
    def self.addLog(text)
      @txt += text + '\n'
    end
    def self.saveLog(text)
      @txt += text
      GlobalMethods.submitLog();
    end
    def self.submitLog()
      File.open("D:\\output.txt", "w") do |file|
          file.write(@txt)
          @txt = ''
      end
    end
    def self.objToStr(obj)
      content = '{';
      obj.instance_variables.each do |var|
        value = obj.instance_variable_get(var)
        content += "#{var}: #{value}, "
      end
      content += "}"
      return content
    end
    def self.openFactoryWindon(type)
      $scene = Scene_Factory.new(type)
      $scene.main
    end
  end

  Thread.new do
    loop do
      sleep(1)
      GlobalMethods.submitLog()
    end
  end

  # Prepare for transition
  Graphics.freeze
  # Make scene object (title screen)
  $scene = Scene_Title.new
  # Call main method as long as $scene is effective
  while $scene != nil
    $scene.main
  end
  # Fade out
  Graphics.transition(20)

rescue Errno::ENOENT
  # Supplement Errno::ENOENT exception
  # If unable to open file, display message and end
  filename = $!.message.sub("No such file or directory - ", "")
  print("Unable to find file #{filename}.")
end
